﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbAccountTest and is intended
    ///     to contain all TmdbAccountTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbAccountTest
    {
        /// <summary>
        ///     A test for TmdbAccount Constructor
        /// </summary>
        [TestMethod]
        public void TmdbAccountConstructorTest()
        {
            var target = new TmdbAccount();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbAccount();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Id = expected;
            int actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for IncludeAdult
        /// </summary>
        [TestMethod]
        public void IncludeAdultTest()
        {
            var target = new TmdbAccount();
            bool expected = new Random().Next( 0, Int32.MaxValue ) % 2 == 0;
            target.IncludeAdult = expected;
            bool actual = target.IncludeAdult;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Iso3166_1
        /// </summary>
        [TestMethod]
        public void Iso3166_1Test()
        {
            var target = new TmdbAccount();
            string expected = Guid.NewGuid().ToString();
            target.Iso3166_1 = expected;
            string actual = target.Iso3166_1;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Iso639_1
        /// </summary>
        [TestMethod]
        public void Iso639_1Test()
        {
            var target = new TmdbAccount();
            string expected = Guid.NewGuid().ToString();
            target.Iso639_1 = expected;
            string actual = target.Iso639_1;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Name
        /// </summary>
        [TestMethod]
        public void NameTest()
        {
            var target = new TmdbAccount();
            string expected = Guid.NewGuid().ToString();
            target.Name = expected;
            string actual = target.Name;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Username
        /// </summary>
        [TestMethod]
        public void UsernameTest()
        {
            var target = new TmdbAccount();
            string expected = Guid.NewGuid().ToString();
            target.Username = expected;
            string actual = target.Username;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\account.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbAccount();
            var jsonContent = File.ReadAllText("account.json.txt");
            var actual = await target.DeserializeJson<TmdbAccount>(jsonContent);

            Assert.AreEqual(5998710, actual.Id);
            Assert.AreEqual("en", actual.Iso639_1);
            Assert.AreEqual("US", actual.Iso3166_1);
            Assert.AreEqual("dave senn", actual.Name);
            Assert.AreEqual(true, actual.IncludeAdult);
            Assert.AreEqual("username...", actual.Username);
        }
    }
}